package com.gopay.common.id;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.Properties;

/**
 * 生成器构建类
 */
public class GeneratorBuilder {

    /**
     * 配置文件路径
     */
    private static final String PROP_PATH = "id.properties";

    private static Logger logger = LoggerFactory.getLogger(GeneratorBuilder.class);

    /**
     * 创建Worker ID 生成器
     * @return
     */
    public static WorkerIdGenerator buildWorkerGenUseProp(){
        logger.info("创建Worker ID 生成器...");
        Properties prop = new Properties();
        try {
            prop.load(GeneratorBuilder.class.getClassLoader().getResourceAsStream(PROP_PATH));
        } catch (IOException e) {
            logger.error("加载id配置文件时出现错误：" + e.getMessage());
            throw new RuntimeException(e);
        }
        return new WorkerIdGenerator(prop);
    }
}
